package com.ruoyi.project.module.accessories.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.accessories.domain.Accessoriess;
import com.ruoyi.project.module.accessories.service.IAccessoriesService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 宠物饰品 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-16
 */
@Controller
@RequestMapping("/module/accessories")
public class AccessoriesController extends BaseController
{
    private String prefix = "module/accessories";
	
	@Autowired
	private IAccessoriesService accessoriesService;
	
	@RequiresPermissions("module:accessories:view")
	@GetMapping()
	public String accessories()
	{
	    return prefix + "/accessories";
	}
	
	/**
	 * 查询宠物饰品列表
	 */
	@RequiresPermissions("module:accessories:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Accessoriess accessories)
	{
		startPage();
        List<Accessoriess> list = accessoriesService.selectAccessoriesList(accessories);
		return getDataTable(list);
	}
	
	/**
	 * 新增宠物饰品
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存宠物饰品
	 */
	@RequiresPermissions("module:accessories:add")
	@Log(title = "宠物饰品", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Accessoriess accessories)
	{		
		return toAjax(accessoriesService.insertAccessories(accessories));
	}

	/**
	 * 修改宠物饰品
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Accessoriess accessories = accessoriesService.selectAccessoriesById(id);
		mmap.put("accessories", accessories);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存宠物饰品
	 */
	@RequiresPermissions("module:accessories:edit")
	@Log(title = "宠物饰品", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Accessoriess accessories)
	{		
		return toAjax(accessoriesService.updateAccessories(accessories));
	}
	
	/**
	 * 删除宠物饰品
	 */
	@RequiresPermissions("module:accessories:remove")
	@Log(title = "宠物饰品", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(accessoriesService.deleteAccessoriesByIds(ids));
	}
	
}
